package com.webflux.sample.webfluxapp.service.impl;

import com.webflux.sample.webfluxapp.entity.MessageEntity;
import com.webflux.sample.webfluxapp.repo.MessageRepo;
import com.webflux.sample.webfluxapp.service.MessageService;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@RequiredArgsConstructor
@Service
public class MessageServiceImpl implements MessageService {

  private final MessageRepo messageRepo;

  @Override
  public List<MessageEntity> findMessages() {
    return messageRepo.findAll();
  }

  @Override
  public MessageEntity findMessageById(Long id) {
    return messageRepo.findById(id).orElse(null);
  }

  @Transactional
  @Override
  public MessageEntity save(MessageEntity message) {
    return messageRepo.save(message);
  }
}
